<%--
  Created by IntelliJ IDEA.
  User: 飞蓬
  Date: 2018/5/1
  Time: 20:20
  To change this template use File | Settings | File Templates.
--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <base href="<%=basePath%>">
    <jsp:include page="../js_top.jsp"></jsp:include>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
    <style type="text/css">
        body{

            background-image:url('/static/loginpage/images/2.jpg');

            background-repeat:no-repeat;

            background-size:cover;

        }
        .table_report{width:540px;margin:15px auto;}
        .table_report tr td{line-height:31px;color:#63666d;font-size:14px;font-family:Arial,Helvetica,"微软雅黑";}
        .table_report tr td a{width:185px;height:38px;line-height:38px;-webkit-border-radius:5px;border-radius:5px;border-color:#b7bacb;display:block;font-size:14px;font-family:"微软雅黑";text-shadow:0 0px 0 rgba(0,0,0,0)!important;background:#b7bacb url(/static/img/images/table_report_icon1.png) no-repeat 60px center;text-align:center;color:#fff;cursor:pointer;text-indent:20px;float:left;margin:0 20px 0 0;}

        .table_report tr td a:hover,.table_report tr:last-child td:last-child a:hover{background-color:#0fb1d6;text-decoration:none;}
        input:focus:invalid:focus, textarea:focus:invalid:focus, select:focus:invalid:focus{border-color:#f59942;}
    </style>
</head>

<body >
<form action="sys/sysUser/save.do" id="saveForm" name="saveForm" method="post">
    <input type="hidden" name="userId" id="userId" value="${user.userId}" />
    <table class="table    table_report" style="margin-top: 100px">
        <tr>
            <td >登陆账号</td>
            <td><input type="text" name="loginName" id="loginName" value="${user.loginName}" placeholder="必填"  required="true"/></td>
            <td>姓名</td><td>
            <input type="text" name="userName" id="userName" value="${user.userName}" placeholder="必填"  required="true"/></td>
        </tr>
        <tr>
            <td>性别</td>
            <td><input type="text" name="sex" id="sex" value="${user.sex}" placeholder="选填"/></td>
            <td>年龄</td><td>
            <input type="text" name="age" id="age" value="${user.age}" placeholder="选填" /></td>
        </tr>
        <tr>
            <td>电话</td>
            <td><input type="text" name="phone" id="phone" value="${user.phone}" placeholder="选填"/></td>
            <td>备注</td>
            <td><input type="text" name="remark" id="remark" value="${user.remark}" placeholder="选填"/></td>
        </tr>
        <tr>
            <td colspan="10">
                <a  style="margin-left: 66px"  href="javascript:register();">注册</a>
                <a href="javascript:cancelregister();">不注册了</a>
            </td>

        </tr>
    </table>
</form>
</body>
<script type="text/javascript">

    function cancelregister() {
        window.location.href='/sys/sysUser/toLogin.do?isfront=1';
    }

    function register(){
        var loginName = $('#loginName').val().trim();
        var loginNameIs = "${user.loginName}";//存在账号则更新
        var userName = $('#userName').val().trim();
        if(loginName === null || loginName === ''){
            $('#loginName').tips({
                side:3,
                msg:'用户名不能为空！',
                bg:'#AE81FF',
                time:3
            });
            $('#loginName').focus();
            return false;
        }
        if(userName === null || userName === ''){
            $('#userName').tips({
                side:3,
                msg:'姓名不能为空！',
                bg:'#AE81FF',
                time:3
            });
            $('#userName').focus();
            return false;
        }
        if((loginNameIs !=null && loginNameIs != '' && loginNameIs != loginName) || loginNameIs === null || loginNameIs === ''){
            var url = '<%=basePath%>sys/sysUser/checkLoginNameExist.do';
            var postData;
            postData = {"loginName":loginName};
            $.post(url,postData,function(data){
                if(data && data==="existUser"){

                    $("#loginName").tips({
                        side : 3,
                        msg : "该账号已存在!",
                        bg : '#FF5080',
                        time : 3
                    });

                }else{
                    $.ajax({
                        cache: true,
                        type: "POST",
                        url:'<%=basePath%>sys/sysUser/save.do',
                        data:$('#saveForm').serialize(),
                        async: false,
                        error: function(request) {
                            layer.msg('<span style="color:white;">插入数据出错 !</span>');
                        },
                        success: function(data) {
                            if(data=true){
                                cancelregister();
                            }
                        }
                    });
                }
            });
        }else{
            $.ajax({
                cache: true,
                type: "POST",
                url:'<%=basePath%>sys/sysUser/save.do',
                data:$('#saveForm').serialize(),
                async: false,
                error: function(request) {
                    layer.msg('<span style="color:white;">更新数据出错 !</span>');
                },
                success: function(data) {
                    if(data=true){
                        cancelregister();
                    }
                }
            });
        }


    }
</script>
</html>
